<?php

// COPYRIGHT DawciuPotter.pl 2012
// ALL RIGHTS RESERVED

require_once "maincore.php";

add_to_head('<style type="text/css">
table.sample {
	border-width: 1px;
	border-spacing: 2px;
	border-style: outset;
	border-color: black;
	border-collapse: collapse;
	background-color: white;
}
table.sample td {
	border-width: 1px;
	padding: 2px;
	border-style: inset;
	border-color: gray;
	background-color: white;
}
</style>
');

require_once THEMES."templates/header.php";

require_once "oazowicze/core.php";

$rangi = getRangi();

if(isset($_GET['id'])){
	$oazowicz = new oazowicz();
	if(!$oazowicz->load($_GET['id'])) redirect("oazowicze.php");
	
	opentable($oazowicz->getImie()." ".$oazowicz->getNazwisko());
	
	echo $oazowicz->getImg(false, "align='left'");
	
	echo "<br /><table class='sample' width='80%'>";
	echo "<tr><td>Imie i nazwisko:</td><td><b>".$oazowicz->getImie()." ".$oazowicz->getNazwisko()."</b></td></tr>";
	echo "<tr><td>Data urodzin:</td><td>".date("d-m-Y", $oazowicz->getUrodziny())."</td></tr>";
	echo "<tr><td>OZK</td><td>".$oazowicz->getOzkNameRank()."</td></tr>";
	echo "<tr><td>ODB</td><td>".$oazowicz->getOdbNameRank()."</td></tr>";
	echo "</table><br /><br />";
	
	closetable();
	
	
	$resulta = dbarray(dbquery("SELECT * FROM `".DB_USERS."` WHERE `user_id` = '".$oazowicz->getUser_id()."'"));
	if($resulta['user_id'] != null){
		
		require_once CLASSES."UserFields.class.php";
		include LOCALE.LOCALESET."user_fields.php";
		
		$user_status = " AND (user_status='0' OR user_status='3' OR user_status='7')";
		if (iADMIN) {
			$user_status = "";
		}
		$result = dbquery(
			"SELECT u.*, s.suspend_reason
			FROM ".DB_USERS." u
			LEFT JOIN ".DB_SUSPENDS." s ON u.user_id=s.suspended_user
			WHERE user_id='".$resulta['user_id']."'".$user_status."
			ORDER BY suspend_date DESC
			LIMIT 1"
		);

		if (dbrows($result)) { $user_data = dbarray($result); } else { redirect("index.php"); }
		add_to_title($locale['global_200'].$locale['u103'].$locale['global_201'].$user_data['user_name']);

		if (iADMIN && checkrights("UG") && $_GET['lookup'] != $userdata['user_id']) {
			if ((isset($_POST['add_to_group'])) && (isset($_POST['user_group']) && isnum($_POST['user_group']))) {
				if (!preg_match("(^\.{$_POST['user_group']}$|\.{$_POST['user_group']}\.|\.{$_POST['user_group']}$)", $user_data['user_groups'])) {
					$result = dbquery("UPDATE ".DB_USERS." SET user_groups='".$user_data['user_groups'].".".$_POST['user_group']."' WHERE user_id='".$_GET['lookup']."'");
				}
				redirect(FUSION_SELF."?lookup=".$user_data['user_id']);
			}
		}

		opentable($locale['u104']." ".$user_data['user_name']);
		$userFields 					= new UserFields();
		$userFields->userData 			= $user_data;
		$userFields->showAdminOptions 	= true;
		$userFields->displayOutput();
		closetable();
	}
}else{
	$result_ozk = dbquery("SELECT * FROM `".DB_PREFIX."oazowicze` WHERE `ozk_ranga` > 0 ORDER BY `ozk_ranga` DESC, `urodziny` ASC, `nazwisko` ASC");
	if(dbrows($result_ozk)){
		opentable("Oazowicze OZK");
		echo "<table class='sample' width='100%'>";
		echo "<tr><td><b>Imie i nazwisko</b></td><td><b>Ranga</b></td><td><b>Data urodzin</b></td></tr>";
		while($element = dbarray($result_ozk)){
			echo "<tr><td><a href='oazowicze.php?id=".$element['id']."'>".$element['imie']." ".$element['nazwisko']."</a></td><td>".$rangi[$element['ozk_ranga']]."</td><td>".date("d-m-Y", $element['urodziny'])."</td></tr>";
		}
		echo "</table>";
		closetable();
	}
	
	$result_odb = dbquery("SELECT * FROM `".DB_PREFIX."oazowicze` WHERE `odb_ranga` > 0 ORDER BY `odb_ranga` DESC, `urodziny` ASC, `nazwisko` ASC");
	if(dbrows($result_odb)){
		opentable("Oazowicze ODB");
		echo "<table class='sample' width='100%'>";
		echo "<tr><td><b>Imie i nazwisko</b></td><td><b>Ranga</b></td><td><b>Data urodzin</b></td></tr>";
		while($element = dbarray($result_odb)){
			echo "<tr><td><a href='oazowicze.php?id=".$element['id']."'>".$element['imie']." ".$element['nazwisko']."</a></td><td>".$rangi[$element['odb_ranga']]."</td><td>".date("d-m-Y", $element['urodziny'])."</td></tr>";
		}
		echo "</table>";
		closetable();
	}
}
require_once THEMES."templates/footer.php";
?>